# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution(object):
    def pathSum(self, root, targetSum):
        ans=[]
        path=[]
        def dfs(node,left):
            if node is None:
                return
            path.append(node.val)
            left-=node.val
            if node.left is None and node.right is None and left==0:
                ans.append(path[:])
            else :
                dfs(node.left,left)
                dfs(node.right,left)
            path.pop()
        dfs(root,targetSum)
        return ans